/**
 * Independent time operation tool to facilitate subsequent switch to dayjs
 */
import moment from "moment";

const DATE_TIMEMILLIS_FORMAT = "YYYY-MM-DD HH:mm:ss";
const DATE_TIME_FORMAT = "YYYY-MM-DD HH:mm";
const DATE_FORMAT = "YYYY-MM-DD ";

export function formatToDateTime(
  date: moment.MomentInput = undefined,
  format = DATE_TIME_FORMAT
): string {
  return moment(date).format(format);
}

export function formatToDate(
  date: moment.MomentInput = undefined,
  format = DATE_FORMAT
): string {
  return moment(date).format(format);
}

export function millis2str(millis: number) {
  return moment(millis).format(DATE_TIMEMILLIS_FORMAT);
}

export const dateUtil = moment;
